<template>
  <div class="unit_information">
    <div class="header_title">
      <span>单位信息</span>
    </div>
    <div class="list">
      <el-form
        ref="alldata"
        :model="alldata"
        :rules="alldatarule"
        :label-position="labelPosition"
        label-width="90px"
        :disabled="!isauth('unit_update')"
      >
        <el-col :span="12">
          <el-form-item label="单位类型" prop="unitType">
              <el-select
                v-model="alldata.unitType"
                placeholder="请选择"
                style="width:180px"
                size="mini" 
                disabled="disabled"
              >
                <el-option
                  v-for="item in unitTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="单位名称:" prop="unitName">
              <el-input v-model="alldata.unitName" size="mini" style="width:180px"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="单位编号:" prop="unitCode">
              <el-input v-model="alldata.unitCode" size="mini" style="width:180px"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="单位地址:">
              <el-input v-model="alldata.unitAddress" size="mini" style="width:180px"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="单位电话:">
              <el-input v-model="alldata.phoneNumber" size="mini" style="width:180px"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系人:">
              <el-input v-model="alldata.linkMan" size="mini" style="width:180px"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="传真:">
              <el-input v-model="alldata.fax" size="mini" style="width:180px"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="网址:">
              <el-input v-model="alldata.website" size="mini" style="width:180px"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item>
            <el-button type="primary" @click="onSubmit()" v-if="isauth('unit_update')">保存信息</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      userGuid: '',
      labelPosition: 'right',
      alldata: {
        // unitName:'',
        // unitCode:'',
        // unitAddress:'',
        // phoneNumber:'',
        // linkMan:'',
        // fax:'',
        // website:''
      },
      alldatarule: {
        unitName: [
          { required: true, message: '单位名称不能为空', trigger: 'blur' }
        ],
        unitCode: [
          { required: true, message: '单位编号不能为空', trigger: 'blur' }
        ]
        // unitAddress:[
        //     { required: true, message: '单位地址不能为空', trigger: 'blur' }
        // ],
        // phoneNumber:[
        //     { required: true, message: '单位电话不能为空', trigger: 'blur' }
        // ],
        // linkMan:[
        //     { required: true, message: '联系人不能为空', trigger: 'blur' }
        // ],
        // fax:[
        //     { required: true, message: '传真不能为空', trigger: 'blur' }
        // ],
      },
      unitTypeList: [
        { label: '系统单位', value: 1 },
        { label: '代理商', value: 50 },
        { label: '学校', value: 100 }
      ]
    }
  },
  created() {
    this.userGuid = sessionStorage.getItem('administrator')
  },
  mounted() {
    this.getuintdata()
  },
  computed: {
    changeschoolid: {
      get() {
        return this.$store.state.user.changeschoolid
      }
    }
  },
  methods: {
    getuintdata() {
      this.$http({
        url: this.$http.adornUrl('/unit/search-unit-detail'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            unitGuid: this.changeschoolid,
            userGuid: this.userGuid
          },
          messageType: this.messageType
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          this.alldata = data.messageContent
          console.log(this.alldata)
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    onSubmit() {
      this.$refs['alldata'].validate(valid => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl('/manager/update-unit-info'),
            method: 'post',
            data: this.$http.adornData({
              messageContent: {
                unitGuid: this.changeschoolid,
                userGuid: this.userGuid,
                unitCode: this.alldata.unitCode,
                unitName: this.alldata.unitName,
                unitAddress: this.alldata.unitAddress,
                phoneNumber: this.alldata.phoneNumber,
                linkMan: this.alldata.linkMan,
                fax: this.alldata.fax,
                website: this.alldata.website
              },
              messageType: this.messageType
            })
          }).then(({ data }) => {
            if (data.messageCode == 200) {
              this.$message({
                showClose: true,
                message: '配置成功',
                type: 'success'
              })
              this.getuintdata()
            } else {
              this.$message.error(data.errorMessage)
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.unit_information {
  padding: 10px;
  .header_title {
    height: 50px;
    line-height: 50px;
    border-bottom: 1px solid #e5e9f2;
    color: #909399;
  }
  .list {
    font-size: 16px;
    font-weight: bold;
    color: #909399;
    padding-top: 20px;
    .el-form-item {
      padding-left: 22px;
      height: 50px;
      line-height: 50px;
      margin-bottom: 0px;
      // padding-top: 18px;
      // border-bottom: 1px solid #e5e9f2;
      width: 100%;
    }
    .el-form-item:last-child {
      border-bottom: 0px solid #e5e9f2;
    }
  }
}
</style>